import type { VNodeChild } from 'vue';

import { tableFieldComponentMap } from '@/components/table/src/component-map';
import type { BasicTableColumn } from '@/components/table';

export function renderTableField(field: BasicTableColumn) {
  return (rowData: Recordable, index: number): VNodeChild => {
    const type = field.fieldType;
    const component = tableFieldComponentMap[type];

    return component
      ? h(component, {
        field,
        index,
        rowData,
      })
      : `不支持的表格字段组件：${field.type}`;
  };
}
